package com.cheryl.springailearn.controller;


import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/function")
@RequiredArgsConstructor
@RestController
public class AIFunctionController {

    private final ChatModel chatModel;

    @GetMapping
    public String testFunction(){
        UserMessage userMessage = new UserMessage("济南天气怎么样？");
        OpenAiChatOptions options = OpenAiChatOptions.builder()
                .withFunction("locationWeatherFunction")
                .withModel("gpt-4-turbo")
                .build();
        ChatResponse call = chatModel.call(
                new Prompt(
                        List.of(userMessage),
                        options
                )
        );
        return call.getResult().getOutput().getContent();
    }

}
